#include <iostream>
#include <string>
#include <unordered_map>
using namespace std;

string eraseLeftChars(string source, unordered_map<char, int> eraseChars) {
    while (source.size() > 0 &&
    eraseChars.find(source[0]) != eraseChars.end()) {
        source = source.substr(1);
    }
    return source;
}

string eraseRightChars(string source, unordered_map<char, int> eraseChars) {
    while (source.size() > 0 &&
    eraseChars.find(source[source.size() - 1]) != eraseChars.end()) {
        source = source.substr(0, source.size() - 1);
    }
    return source;
}

string eraseSideChars(string source, unordered_map<char, int> eraseChars) {
    source = eraseLeftChars(source, eraseChars);
    source = eraseRightChars(source, eraseChars);
    return source;
}

int main() {
    unordered_map<char, int> eraseChars;
    string target; getline(cin, target);
    string eraser; getline(cin, eraser);
    for (int i = 0; i < eraser.size(); i++) {
        eraseChars.insert(pair<char, int>(eraser[i], 1));
    }
    cout << eraseLeftChars(target, eraseChars) << endl;
    cout << eraseRightChars(target, eraseChars) << endl;
    cout << eraseSideChars(target, eraseChars) << endl;
}